package com.hospital.mapper;

import com.hospital.entity.Employee;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface EmployeeMapper {

    // 获取所有员工信息
    @Select("select * from table_employee")
    List<Employee> getAllEmployee();

    // 通过Eid获取员工信息
    @Select("select * from table_employee where EMPLOYEE_ID = #{Eid}")
    Employee getEmployeeByID(int Eid);

    // 主要方式：通过电话号码获取员工信息
    @Select("select * from table_employee where EMPLOYEE_PHONE = #{phone}")
    Employee getEmployeeByPhone(String phone);

    // 通过科室名称查询满足条件的所有员工
    @Select("SELECT table_employee.* FROM table_employee NATURAL JOIN table_offices where table_offices.OFFICE_NAME = #{OfficeName}")
    List<Employee> getEmployeesByOffice(String OfficeName);

    // 通过电话号码查询用户的密码
    @Select("SELECT EMPLOYEE_PASSWORD FROM table_employee where EMPLOYEE_PHONE = #{phone}")
    String getEmployeePasswordByPhone(String phone);

    // 添加新员工
    @Insert("INSERT INTO table_employee" +
            "(EMPLOYEE_PASSWORD, EMPLOYEE_NAME, EMPLOYEE_BIRTH, EMPLOYEE_GENDER, " +
            "EMPLOYEE_PHONE, OFFICE_ID, EMPLOYEE_POSITION, EMPLOYEE_GRADE)" +
            "VALUES(#{employee_password}, #{employee_name}, #{employee_birth}, " +
            "#{employee_gender}, #{employee_phone}, #{office_id}, #{employee_position}" +
            ", #{employee_grade})")
    int insertEmployee(Employee employee);

    // 更新员工数据
    @Update("UPDATE table_employee SET EMPLOYEE_PASSWORD=#{employee_password}," +
            "EMPLOYEE_NAME=#{employee_name},EMPLOYEE_BIRTH=#{employee_birth}," +
            "EMPLOYEE_GENDER=#{employee_gender},EMPLOYEE_PHONE=#{employee_phone}," +
            "OFFICE_ID=#{office_id},EMPLOYEE_POSITION=#{employee_position},EMPLOYEE_GRADE=" +
            "#{employee_grade} WHERE EMPLOYEE_ID = #{employee_id}"
    )
    int updateEmployee(Employee employee);
}
